//
//  MyScrollView.m
//  MyScrollView
//
//  Created by 李 亚春 on 13-04-07.
//  Copyright (c) 2012年 epoint. All rights reserved.
//
#import "MyScrollView.h"

@implementation MyScrollView

@synthesize image;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        self.delegate = self;
        //		self.minimumZoomScale = 0.5;
        //		self.maximumZoomScale = 2.5;
        self.showsVerticalScrollIndicator = NO;
        self.showsHorizontalScrollIndicator = NO;
        
        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        imageView.contentMode = UIViewContentModeScaleToFill;
        [self addSubview:imageView];
    }
    return self;
}



- (void)setImage:(UIImage *)img {
    imageView.image = img;
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return imageView;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    CGFloat zs = scrollView.zoomScale;
    zs = MAX(zs, 1.0);
    zs = MIN(zs, 2.0);
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    scrollView.zoomScale = zs;
    [UIView commitAnimations];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    
    if ([touch tapCount] == 2) {
        CGFloat zs = self.zoomScale;
        zs = (zs == 1.0) ? 2.0 : 1.0;
        
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        self.zoomScale = zs;
        [UIView commitAnimations];
    }
}

#pragma mark 触发点击事件
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    
    [self.dele touchSV];
}



@end